const myRequest = require('../../tool/myRequest')
const daoUser = require('../../dao/daoUser')
const cheerio = require('cheerio');


// 解析分类列表里面的所有标签tag
function tttt(page) {
  myRequest('http://localhost:8422/pages/test.html', {}).then(d => {
    // myRequest('https://manwast.cc/booklist?img_host=4&page=' + page, {}).then(d => {
    if (d.status == 200) {
      const $ = cheerio.load(d.data);
      let aTags = $('a.panel-tag');
      let arr = [];
      if (aTags.length == 0) { console.log(`==*****=====没有找到对应的目标====***===`,); return };
      aTags.each((num, item) => {
        let v = $(item).attr('data-val').trim();
        v && arr.push(`(${num},'${v}')`);
      })
      daoUser.addTags([arr.join(',')]).then(d => { console.log(`d`, d) }).catch(e => console.log(`e`, e));
      console.log(``, arr.join(','))
    } else console.log(`请求失败`,)
  }).catch(e => { console.log(`e`, e) })
}
// tttt()


// 获取tags标签
// daoUser.getTags().then(d => console.log(`d`, d))


module.exports = {
  getTags() {
    return daoUser.getTagsFormIs_searchLimit()

    // return new Promise((resolve, reject) => {
    //   resolve(daoUser.getTagsFormIs_searchLimit())
    // })
  }
}